#!/usr/bin/perl

require "./dftcfg-lib.pl";

my (@md, $i, $rqrb, @line, $tableng, $rqrb);
my ($err_msg, $log_ev, $log_msg, $out);

#&header($text{'index_title'}, "", "index", 0, 1);

&ReadParse();

unless($in{'checkmd'})
{
	$log_ev = $text{'log_ev_dft_fail_post'};
	$log_msg= $text{'log_msg_dft_fail_post'};
	nas_syslog($text{'modulename'}, 'naslog_warning', $log_ev, $log_msg);
	$err_msg = $text{'error_msg_dft_fail_post'};
	goto ERROR_OUT;
}

@md = split("\0", $in{'checkmd'});
&save_dftcfgtab(\@md);

$rqrb = &exec_dftcfgtab();

if($rqrb > 0)
{
	my $out = &ez_system($config{'cmd_dft_boot'});
	$log_ev = $text{'log_ev_dft_reboot'};
	$log_msg= $text{'log_msg_dft_reboot'};
	nas_syslog($text{'modulename'}, 'naslog_info', $log_ev, $log_msg);

#	print "<p>reboot";
	$out = &ez_system("shutdown", "-r", "now");
}
else
{
	$log_ev = $text{'log_ev_dft_miniserv_restart'};
	$log_msg= $text{'log_msg_dft_miniserv_restart'};
	nas_syslog($text{'modulename'}, 'naslog_info', $log_ev, $log_msg);

        &restart_miniserv();	
}

$log_ev = $text{'log_ev_dft_success'};
$log_msg= $text{'log_msg_dft_success'};
nas_syslog($text{'modulename'}, 'naslog_info', $log_ev, $log_msg);

for($i = 0; $i < @md; $i++)
{
	if($md[$i] eq "setpass")
	{
		&redirect( "/session_login.cgi?logout=1" );
	}
}

&redirect("");

ERROR_OUT:
&error_setup($text{'post_err_title'});
&error($err_msg);

#&footer("", $text{'index_title'});
